const socket = {
  state: {
    requestCach: [],
    loginTransition: false,
    loginAccount: false
  },

  mutations: {
    SOCKET_OPEN: (state, status) => {
      state.socketOpen = status;
    },
    LOGIN_TRANSITION: (state, data) => {
      state.loginTransition = data;
    },
    REQUEST_CACH: (state, data) => {
      state.requestCach.push(data);
    },
    LOGIN_ACCOUNT: (state, data) => {
      state.loginAccount = data;
    }
  },

  actions: {
    // 检测链接是否打开
    socketOpen({ commit }, data) {
      return new Promise(() => {
        commit("SOCKET_OPEN", data);
      });
    },
    // 检测是否保持登录
    loginTransition({ commit }, data) {
      return new Promise(() => {
        commit("LOGIN_TRANSITION", data);
      });
    },
    // 检测是否账号登录
    loginAccount({ commit }, data) {
      return new Promise(() => {
        commit("LOGIN_ACCOUNT", data);
      });
    },
    // 保存发送数据
    requestCach({ commit }, data) {
      return new Promise(() => {
        commit("REQUEST_CACH", data);
      });
    }
  }
};

export default socket;
